/*
 * Copyright (c) 2015, Potevio Information Technology Co., Ltd. 
 * All rights reserved.
 * POTEVIO PROPRIETARY/CONFIDENTIAL.
 */
package com.cpit.platform.common.entity;
/**
 * 表格查询的分页结果封装。该结构为jqGrid使用。
 * @author zhanghaibin
 * @date 2016-01-05
 */
import java.util.ArrayList;
import java.util.List;

public class TableJsonData {
	/** 当前页 */
	private String page = "";
	/** 总页数 */
	private String total = "";
	/** 总记录数 */
	private String records = "";
	/** 记录数据 */
	private List<TableRow> rows = new ArrayList<TableRow>();
	
	@SuppressWarnings("rawtypes")
	public TableJsonData(String page, String total,
			String records, List serviceData) {
		super();
		this.page = page;
		this.total = total;
		this.records = records;
		
		int len = serviceData.size();
		if (serviceData != null || len > 0) {
			for (int i = 0; i < len; i++) {
				TableRow tr = new TableRow(String.valueOf(i), serviceData.get(i));
				rows.add(tr);
			}
		}
	}
	
	@SuppressWarnings("rawtypes")
	public TableJsonData(TableDataQueryCondition cond, long count, List serviceData) {
		super();
		this.page = cond.getPage();
		int perPage = Integer.parseInt(cond.getRows());
		long rem = count % perPage;
		if (rem == 0) {
			this.total = String.valueOf(count / perPage);
		} else {
			this.total = String.valueOf(count / perPage + 1);
		}
		this.records = String.valueOf(count);
		int len = serviceData.size();
		if (serviceData != null || len > 0) {
			for (int i = 0; i < len; i++) {
				TableRow tr = new TableRow(String.valueOf(i), serviceData.get(i));
				rows.add(tr);
			}
		}
	}

	public String getPage() {
		return page;
	}

	public void setPage(String page) {
		this.page = page;
	}

	public String getTotal() {
		return total;
	}

	public void setTotal(String total) {
		this.total = total;
	}

	public String getRecords() {
		return records;
	}

	public void setRecords(String records) {
		this.records = records;
	}

	public List<TableRow> getRows() {
		return rows;
	}

	public void setRows(List<TableRow> rows) {
		this.rows = rows;
	}

	@Override
	public String toString() {
		return "TableJsonData [page=" + page + ", total=" + total + ", records=" + records + ", rows=" + rows + "]";
	}
	
	
}
